package com.study_security.controller;


import com.study_security.domain.ResponseResult;
import com.study_security.entity.User;
import com.study_security.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
public class LoginController {
    @Autowired
    private LoginService loginService;

//    @Autowired
//    private VerificationCodeService verificationCodeService;

//    @PostMapping("/user/sendVerificationCode")
//    public ResponseResult sendVerificationCode(@RequestParam String phoneNumber) {
//        try {
//            verificationCodeService.sendVerificationCode(phoneNumber);
//            return new ResponseResult(200, "验证码发送成功");
//        } catch (Exception e) {
//            return new ResponseResult(500, "验证码发送失败");
//        }
//    }

    @PostMapping("/user/login")
    public ResponseResult login(@RequestBody User user) {
        //登录
        return loginService.login(user);
    }

    @RequestMapping("/user/logout")
    public ResponseResult logout() {
        return loginService.logout();
    }

    @PostMapping("/user/register")
    public ResponseResult register(@RequestBody User user) {
        return loginService.register(user);
    }
    @PostMapping("/user/sendVerificationCode")
    public ResponseResult sendVerificationCode(@RequestBody Map<String, String> request) {
        String email = request.get("email");
        return loginService.sendVerificationCode(email);
    }
    @PostMapping("/user/forgotPassword")
    public ResponseResult forgotPassword(@RequestBody Map<String, String> request) {
        String email = request.get("email");
        String newPassword = request.get("newPassword");
        String verificationCode = request.get("verificationCode");
        return loginService.forgotPassword(email, newPassword, verificationCode);
    }


}
